﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Catalyst.Mvc.Extensions;
using System.Reflection;

namespace Catalyst.Mvc
{
	public static class HtmlHelper
	{
		public static LiteContext Lite(this System.Web.Mvc.HtmlHelper helper)
		{
			return new LiteContext(helper);
		}

		public static MvcHtmlString SubMenu(this System.Web.Mvc.HtmlHelper helper)
		{
			UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection);
			
			string menu = "";
			
			if (helper.ViewData["submenu_links"] != null)
			{
				SortedDictionary<int, string> links = (SortedDictionary<int, string>)helper.ViewData["submenu_links"];

				foreach (var link in links)
				{
					menu += String.Format("<a href=\"{0}\">{1}</a> ", urlHelper.Action(link.Value), link.Value);
				}
			}

			return MvcHtmlString.Create(menu);
		}

		//public static MvcHtmlString RenderMenu(this HtmlHelper helper)
		//{
		//    var somePage = helper ViewContext.HttpContext.Request.RawUrl;
		//    var menu = lookupMenuBasedOnPage(somePage);

		//    return MvcHtmlString.Create(menu.Render());
		//} 

	}
}
